package com.font.web.zhongyao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.font.bean.Medicine;
import com.font.bean.Prescription;
import com.font.bean.result.Result;
import com.font.service.PrescriptionService;
import com.font.utils.PageListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/prescription")
public class PrescriptionController {

    @Autowired
    PrescriptionService prescriptionService;

    @GetMapping("prescriptionList")
    public Result prescriptionList(
            @RequestParam(value = "prescriptionName", required = false) String prescriptionName,
            @RequestParam(value = "prescriptionFunction", required = false) String prescriptionFunction,
            @RequestParam(value = "prescriptionTypeKey", required = false) String prescriptionType,
            @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "1") Integer pageSize
    ) {

        QueryWrapper<Medicine> queryWrapper = new QueryWrapper<Medicine>()
                .eq(StrUtil.isNotBlank(prescriptionName),"prescription_name",prescriptionName);


        List<Prescription> prescriptions = prescriptionService.preList(prescriptionName, prescriptionFunction, prescriptionType, currentPage, pageSize);
        IPage<Prescription> prescriptionIPage = PageListUtils.listToPage(prescriptions, currentPage, pageSize);

        return Result.success(prescriptionIPage);
    }

    @GetMapping("countMap")
    public Map<String,Object> countMap(){
      return prescriptionService.countMap();
    }
}
